

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Quickstart &mdash; CodeCarbon 3.1.1 documentation</title>
      <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
      <link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />

  
      <script src="_static/jquery.js?v=5d32c60e"></script>
      <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
      <script src="_static/documentation_options.js?v=796a81b5"></script>
      <script src="_static/doctools.js?v=9bcbadda"></script>
      <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="_static/js/theme.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="CodeCarbon API" href="api.html" />
    <link rel="prev" title="Installing CodeCarbon" href="installation.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="index.html" class="icon icon-home">
            CodeCarbon
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <p class="caption" role="heading"><span class="caption-text">Introduction</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="motivation.html">Motivation</a></li>
<li class="toctree-l1"><a class="reference internal" href="methodology.html">Methodology</a></li>
<li class="toctree-l1"><a class="reference internal" href="rapl.html">RAPL Metrics</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_examples.html">Model Comparisons</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Getting Started</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installing CodeCarbon</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Quickstart</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#online-mode">Online Mode</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#command-line">Command line</a></li>
<li class="toctree-l3"><a class="reference internal" href="#explicit-object">Explicit Object</a></li>
<li class="toctree-l3"><a class="reference internal" href="#context-manager">Context manager</a></li>
<li class="toctree-l3"><a class="reference internal" href="#decorator">Decorator</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#offline-mode">Offline Mode</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id1">Explicit Object</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id2">Context manager</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">Decorator</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="#configuration">Configuration</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#configuration-priority">Configuration priority</a></li>
<li class="toctree-l2"><a class="reference internal" href="#access-internet-through-proxy-server">Access internet through proxy server</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="api.html">CodeCarbon API</a></li>
<li class="toctree-l1"><a class="reference internal" href="parameters.html">Parameters</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="comet.html">Comet Integration</a></li>
<li class="toctree-l1"><a class="reference internal" href="advanced_installation.html">Advanced Installation</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Logging</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="output.html">Output</a></li>
<li class="toctree-l1"><a class="reference internal" href="to_logger.html">Collecting emissions to a logger</a></li>
<li class="toctree-l1"><a class="reference internal" href="visualize.html">Visualize</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">CodeCarbon</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
      <li class="breadcrumb-item active">Quickstart</li>
      <li class="wy-breadcrumbs-aside">
            <a href="_sources/usage.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="quickstart">
<span id="usage"></span><h1>Quickstart<a class="headerlink" href="#quickstart" title="Link to this heading"></a></h1>
<p>The CO2 tracking tool can be used along with any computing framework. It supports both <code class="docutils literal notranslate"><span class="pre">online</span></code> (with internet access) and
<code class="docutils literal notranslate"><span class="pre">offline</span></code> (without internet access) modes. The tracker can be used in the following ways:</p>
<section id="online-mode">
<h2>Online Mode<a class="headerlink" href="#online-mode" title="Link to this heading"></a></h2>
<p>When the environment has internet access, the <code class="docutils literal notranslate"><span class="pre">EmissionsTracker</span></code> object or the <code class="docutils literal notranslate"><span class="pre">track_emissions</span></code> decorator can be used, which has
the <code class="docutils literal notranslate"><span class="pre">offline</span></code> parameter set to <code class="docutils literal notranslate"><span class="pre">False</span></code> by default.</p>
<section id="command-line">
<h3>Command line<a class="headerlink" href="#command-line" title="Link to this heading"></a></h3>
<p>Create a minimal configuration file (just follow the prompts) :</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">codecarbon config</span>
</pre></div>
</div>
<a class="reference external image-reference" href="https://asciinema.org/a/667970"><img alt="Init config" class="align-center" src="https://asciinema.org/a/667970.svg" />
</a>
<p>You can use the same command to modify an existing config :</p>
<a class="reference external image-reference" href="https://asciinema.org/a/667971"><img alt="Modify config" class="align-center" src="https://asciinema.org/a/667971.svg" />
</a>
<p>If you want to track the emissions of a computer without having to modify your code, you can use :</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">codecarbon monitor</span>
</pre></div>
</div>
<p>You have to stop the monitoring manually with <code class="docutils literal notranslate"><span class="pre">Ctrl+C</span></code>.</p>
<p>In the following example you will see how to use the CLI to monitor all the emissions of you computer and sending everything
to an API running on “localhost:8008” (Or you can start a private local API with “docker-compose up”). Using the public API with
this is not supported yet (coming soon!)</p>
<a class="reference external image-reference" href="https://asciinema.org/a/667984"><img alt="Monitor example" class="align-center" src="https://asciinema.org/a/667984.svg" />
</a>
<p>The command line could also works without internet by providing the country code like this:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">codecarbon monitor --offline --country-iso-code FRA</span>
</pre></div>
</div>
<p>Implementing CodeCarbon in your code allows you to track the emissions of a specific block of code.</p>
</section>
<section id="explicit-object">
<h3>Explicit Object<a class="headerlink" href="#explicit-object" title="Link to this heading"></a></h3>
<p>In the case of absence of a single entry and stop point for the training code base, users can instantiate a <code class="docutils literal notranslate"><span class="pre">EmissionsTracker</span></code> object and
pass it as a parameter to function calls to start and stop the emissions tracking of the compute section.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">EmissionsTracker</span>
<span class="n">tracker</span> <span class="o">=</span> <span class="n">EmissionsTracker</span><span class="p">()</span>
<span class="n">tracker</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
     <span class="c1"># Compute intensive code goes here</span>
     <span class="n">_</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">finally</span><span class="p">:</span>
     <span class="n">tracker</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
<p>This mode is recommended when using a Jupyter Notebook. You call <code class="docutils literal notranslate"><span class="pre">tracker.start()</span></code> at the beginning of the Notebook, and call <code class="docutils literal notranslate"><span class="pre">tracker.stop()</span></code> in the last cell.</p>
<p>This mode also allows you to record the monitoring with <code class="docutils literal notranslate"><span class="pre">tracker.flush()</span></code> that writes the emissions to disk or call the API depending on the configuration, but keep running the experiment.</p>
<p>If you want to monitor small piece of code, like a model inference, you could use the task manager:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
    <span class="n">tracker</span> <span class="o">=</span> <span class="n">EmissionsTracker</span><span class="p">(</span><span class="n">project_name</span><span class="o">=</span><span class="s2">&quot;bert_inference&quot;</span><span class="p">,</span> <span class="n">measure_power_secs</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="n">tracker</span><span class="o">.</span><span class="n">start_task</span><span class="p">(</span><span class="s2">&quot;load dataset&quot;</span><span class="p">)</span>
    <span class="n">dataset</span> <span class="o">=</span> <span class="n">load_dataset</span><span class="p">(</span><span class="s2">&quot;imdb&quot;</span><span class="p">,</span> <span class="n">split</span><span class="o">=</span><span class="s2">&quot;test&quot;</span><span class="p">)</span>
    <span class="n">imdb_emissions</span> <span class="o">=</span> <span class="n">tracker</span><span class="o">.</span><span class="n">stop_task</span><span class="p">()</span>
    <span class="n">tracker</span><span class="o">.</span><span class="n">start_task</span><span class="p">(</span><span class="s2">&quot;build model&quot;</span><span class="p">)</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">build_model</span><span class="p">()</span>
    <span class="n">model_emissions</span> <span class="o">=</span> <span class="n">tracker</span><span class="o">.</span><span class="n">stop_task</span><span class="p">()</span>
<span class="k">finally</span><span class="p">:</span>
    <span class="n">_</span> <span class="o">=</span> <span class="n">tracker</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
<p>This way CodeCarbon will track the emissions of each task .
The task will not be written to disk to prevent overhead, you have to get the results from the return of <code class="docutils literal notranslate"><span class="pre">stop_task()</span></code>.
If no name is provided, CodeCarbon will generate a uuid.</p>
<p>Please note that you can’t use task mode and normal mode at the same time. Because <code class="docutils literal notranslate"><span class="pre">start_task</span></code> will stop the scheduler as we do not want it to interfere with the task measurement.</p>
</section>
<section id="context-manager">
<h3>Context manager<a class="headerlink" href="#context-manager" title="Link to this heading"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">Emissions</span> <span class="pre">tracker</span></code> also works as a context manager.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">EmissionsTracker</span>

<span class="k">with</span> <span class="n">EmissionsTracker</span><span class="p">()</span> <span class="k">as</span> <span class="n">tracker</span><span class="p">:</span>
    <span class="c1"># Compute intensive training code goes here</span>
</pre></div>
</div>
<p>This mode is recommended when you want to monitor a specific block of code.</p>
</section>
<section id="decorator">
<h3>Decorator<a class="headerlink" href="#decorator" title="Link to this heading"></a></h3>
<p>In case the training code base is wrapped in a function, users can use the decorator <code class="docutils literal notranslate"><span class="pre">&#64;track_emissions</span></code> within the function to enable tracking
emissions of the training code.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">track_emissions</span>

<span class="nd">@track_emissions</span>
<span class="k">def</span><span class="w"> </span><span class="nf">training_loop</span><span class="p">():</span>
    <span class="c1"># Compute intensive training code goes here</span>
</pre></div>
</div>
<p>This mode is recommended if you have a training function.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This will write a csv file named emissions.csv in the current directory</p>
</div>
</section>
</section>
<section id="offline-mode">
<h2>Offline Mode<a class="headerlink" href="#offline-mode" title="Link to this heading"></a></h2>
<p>An offline version is available to support restricted environments without internet access. The internal computations remain unchanged; however,
a <code class="docutils literal notranslate"><span class="pre">country_iso_code</span></code> parameter, which corresponds to the 3-letter alphabet ISO Code of the country where the compute infrastructure is hosted, is required to fetch Carbon Intensity details of the regional electricity used. A complete list of country ISO codes can be found on <a class="reference external" href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">Wikipedia</a>.</p>
<section id="id1">
<h3>Explicit Object<a class="headerlink" href="#id1" title="Link to this heading"></a></h3>
<p>Developers can use the <code class="docutils literal notranslate"><span class="pre">OfflineEmissionsTracker</span></code> object to track emissions as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">OfflineEmissionsTracker</span>
<span class="n">tracker</span> <span class="o">=</span> <span class="n">OfflineEmissionsTracker</span><span class="p">(</span><span class="n">country_iso_code</span><span class="o">=</span><span class="s2">&quot;CAN&quot;</span><span class="p">)</span>
<span class="n">tracker</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="c1"># GPU intensive training code</span>
<span class="n">tracker</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="id2">
<h3>Context manager<a class="headerlink" href="#id2" title="Link to this heading"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">OfflineEmissionsTracker</span></code> also works as a context manager</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">OfflineEmissionsTracker</span>

<span class="k">with</span> <span class="n">OfflineEmissionsTracker</span><span class="p">()</span> <span class="k">as</span> <span class="n">tracker</span><span class="p">:</span>
<span class="c1"># GPU intensive training code  goes here</span>
</pre></div>
</div>
</section>
<section id="id3">
<h3>Decorator<a class="headerlink" href="#id3" title="Link to this heading"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">track_emissions</span></code> decorator in offline mode requires following two parameters:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">offline</span></code> needs to be set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, which defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> for online mode.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">country_iso_code</span></code> the 3-letter alphabet ISO Code of the country where the compute infrastructure is hosted</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">codecarbon</span><span class="w"> </span><span class="kn">import</span> <span class="n">track_emissions</span>
<span class="nd">@track_emissions</span><span class="p">(</span><span class="n">offline</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">country_iso_code</span><span class="o">=</span><span class="s2">&quot;CAN&quot;</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">training_loop</span><span class="p">():</span>
    <span class="c1"># training code goes here</span>
    <span class="k">pass</span>
</pre></div>
</div>
<p>The Carbon emissions will be saved to a <code class="docutils literal notranslate"><span class="pre">emissions.csv</span></code> file in the same directory. Please refer to the <a class="reference internal" href="parameters.html#parameters"><span class="std std-ref">complete API</span></a> for
additional parameters and configuration options.</p>
</section>
</section>
</section>
<section id="configuration">
<h1>Configuration<a class="headerlink" href="#configuration" title="Link to this heading"></a></h1>
<section id="configuration-priority">
<h2>Configuration priority<a class="headerlink" href="#configuration-priority" title="Link to this heading"></a></h2>
<dl class="simple">
<dt>CodeCarbon is structured so that you can configure it in a hierarchical manner:</dt><dd><ul class="simple">
<li><p><em>global</em> parameters in your home folder <code class="docutils literal notranslate"><span class="pre">~/.codecarbon.config</span></code></p></li>
<li><p><em>local</em> parameters (with respect to the current working directory) in <code class="docutils literal notranslate"><span class="pre">./.codecarbon.config</span></code></p></li>
<li><p><em>environment variables</em> parameters starting with <code class="docutils literal notranslate"><span class="pre">CODECARBON_</span></code></p></li>
<li><p><em>script</em> parameters in the tracker’s initialization as <code class="docutils literal notranslate"><span class="pre">EmissionsTracker(param=value)</span></code></p></li>
</ul>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Configuration files <strong>must</strong> be named <code class="docutils literal notranslate"><span class="pre">.codecarbon.config</span></code> and start with a section header <code class="docutils literal notranslate"><span class="pre">[codecarbon]</span></code> as the first line in the file.</p>
</div>
<p>For instance:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">~/.codecarbon.config</span></code></p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>codecarbon<span class="o">]</span>
<span class="nv">measure_power_secs</span><span class="o">=</span><span class="m">10</span>
<span class="nv">save_to_file</span><span class="o">=</span>local-overwrite
<span class="nv">emissions_endpoint</span><span class="o">=</span>localhost:7777
</pre></div>
</div>
</div></blockquote>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">./.codecarbon.config</span></code> will override <code class="docutils literal notranslate"><span class="pre">~/.codecarbon.config</span></code> if the same parameter is set in both files :</p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>codecarbon<span class="o">]</span>
<span class="nv">save_to_file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="nv">output_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>/Users/victor/emissions
<span class="nv">electricitymaps_api_token</span><span class="o">=</span>script-overwrite
<span class="nv">experiment_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>235b1da5-aaaa-aaaa-aaaa-893681599d2c
<span class="nv">log_level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>DEBUG
<span class="nv">tracking_mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>process
</pre></div>
</div>
</div></blockquote>
</li>
<li><p>environment variables will override <code class="docutils literal notranslate"><span class="pre">./.codecarbon.config</span></code> if the same parameter is set in both files :</p>
<blockquote>
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span><span class="w"> </span><span class="nv">CODECARBON_GPU_IDS</span><span class="o">=</span><span class="s2">&quot;0, 1&quot;</span>
<span class="nb">export</span><span class="w"> </span><span class="nv">CODECARBON_LOG_LEVEL</span><span class="o">=</span><span class="s2">&quot;WARNING&quot;</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p>script parameters will override environment variables if the same parameter is set in both:</p>
<blockquote>
<div><div class="highlight-python notranslate"><div class="highlight"><pre><span></span> <span class="n">EmissionsTracker</span><span class="p">(</span>
<span class="n">api_call_interval</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span>
<span class="n">save_to_api</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">electricitymaps_api_token</span><span class="o">=</span><span class="s2">&quot;some-token&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
<p>Yields attributes:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s2">&quot;measure_power_secs&quot;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span>  <span class="c1"># from ~/.codecarbon.config</span>
    <span class="s2">&quot;save_to_file&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>   <span class="c1"># from ./.codecarbon.config (override ~/.codecarbon.config)</span>
    <span class="s2">&quot;api_call_interval&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="c1"># from script</span>
    <span class="s2">&quot;save_to_api&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>   <span class="c1"># from script</span>
    <span class="s2">&quot;experiment_id&quot;</span><span class="p">:</span> <span class="s2">&quot;235b1da5-aaaa-aaaa-aaaa-893681599d2c&quot;</span><span class="p">,</span> <span class="c1"># from ./.codecarbon.config</span>
    <span class="s2">&quot;log_level&quot;</span><span class="p">:</span> <span class="s2">&quot;WARNING&quot;</span><span class="p">,</span> <span class="c1"># from environment variable (override ./.codecarbon.config)</span>
    <span class="s2">&quot;tracking_mode&quot;</span><span class="p">:</span> <span class="s2">&quot;process&quot;</span><span class="p">,</span> <span class="c1"># from ./.codecarbon.config</span>
    <span class="s2">&quot;emissions_endpoint&quot;</span><span class="p">:</span> <span class="s2">&quot;localhost:7777&quot;</span><span class="p">,</span> <span class="c1"># from ~/.codecarbon.config</span>
    <span class="s2">&quot;output_dir&quot;</span><span class="p">:</span> <span class="s2">&quot;/Users/victor/emissions&quot;</span><span class="p">,</span> <span class="c1"># from ./.codecarbon.config</span>
    <span class="s2">&quot;electricitymaps_api_token&quot;</span><span class="p">:</span> <span class="s2">&quot;some-token&quot;</span><span class="p">,</span> <span class="c1"># from script (override ./.codecarbon.config)</span>
    <span class="s2">&quot;gpu_ids&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="c1"># from environment variable</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you’re wondering about the configuration files’ syntax, be aware that under the hood <code class="docutils literal notranslate"><span class="pre">codecarbon</span></code> uses <a class="reference external" href="https://docs.python.org/3/library/configparser.html#module-configparser"><code class="docutils literal notranslate"><span class="pre">ConfigParser</span></code></a> which relies on the <a class="reference external" href="https://docs.python.org/3/library/configparser.html#supported-ini-file-structure">INI syntax</a>.</p>
</div>
</section>
<section id="access-internet-through-proxy-server">
<h2>Access internet through proxy server<a class="headerlink" href="#access-internet-through-proxy-server" title="Link to this heading"></a></h2>
<p>If you need a proxy to access internet, which is needed to call a Web API, like <a class="reference external" href="https://api.codecarbon.io/docs">Codecarbon API</a>, you have to set environment variable <code class="docutils literal notranslate"><span class="pre">HTTPS_PROXY</span></code>, or <em>HTTP_PROXY</em> if calling an <code class="docutils literal notranslate"><span class="pre">http://</span></code> endpoint.</p>
<p>You could do it in your shell:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span><span class="w"> </span><span class="nv">HTTPS_PROXY</span><span class="o">=</span><span class="s2">&quot;http://0.0.0.0:0000&quot;</span>
</pre></div>
</div>
<p>Or in your Python code:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>

<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;HTTPS_PROXY&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;http://0.0.0.0:0000&quot;</span>
</pre></div>
</div>
<p>For more information, please read the <a class="reference external" href="https://requests.readthedocs.io/en/latest/user/advanced/#proxies">requests library proxy documentation</a></p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="installation.html" class="btn btn-neutral float-left" title="Installing CodeCarbon" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="api.html" class="btn btn-neutral float-right" title="CodeCarbon API" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2020, BCG GAMMA, Comet.ml, Haverford College, MILA.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>